"""
__project__ = 'thc'
__file_name__ = 'dataCsv'
__author__ = 'thc'
__time__ = '2021/1/4/004 11:15'
__product_name = PyCharm
-*- coding:utf-8 -*-
"""

import csv


def test_read1():
    csvFile = open('test_data.csv', 'r')
    reader = csv.reader(csvFile)
    for i in reader:
        print(i)
    csvFile.close()

def test_read2():
    with open('test_data.csv', 'r') as csvFile:
        reader = csv.reader(csvFile)
        for i in reader:
            print(i)

def test_writer1():
    csvFile = open('test_data2.csv', 'w', newline='')
    writer = csv.writer(csvFile)
    data = [['郎平', '排球'], ['姚明', '篮球']]
    for i in data:
        writer.writerow(i)
    csvFile.close()

def test_writer2():
    csvFile = open('test_data3.csv', 'w', newline='')
    writer = csv.writer(csvFile)
    data = {'a': 123, 'b': 456}
    for i in data:
        writer.writerow([i, data[i]])
    csvFile.close()




if __name__ == '__main__':
    # test_read1()
    # test_read2()
    # test_writer1()
    test_writer2()